const formidable = require('formidable');
const {Article} = require('../../model/article');
const path = require('path');
module.exports = async (req, res) => {
	const form = new formidable.IncomingForm();
	// const form = formidable({ multiples: true });
	form.uploadDir = path.join(__dirname, '../', '../', 'public', 'uploads');
	form.keepExtensions = true;
	form.parse(req, async (err, fields, files) => {
		await Article.updateOne({_id: req.query.id}, {
			title: fields.title,
			author: fields.author,
			publishDate: fields.publishDate,
			cover: files.cover.path.split('public')[1],
			content: fields.content
		});
		res.redirect('/admin/article');
	});
	
}